﻿using System;
using System.Web.Security;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Skyworth.CRM.Common
{
    public class Encrypt
    {
        /// <summary>
        /// MD5加密
        /// </summary>
        /// <param name="str">要加密的字符串</param>
        /// <param name="code">位数：默认为32位</param>
        /// <returns></returns>
        public static string MD5(string str, int code)
        {
            if (code == 16)   //16位MD5加密（取32位加密的9~25字符）   
            {
                return FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);
            }
            else//32位加密（默认为32位）
            {
                return FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();
            }
        }
    }
}
